<template>
  <div id="app">
    <h1>房间管理系统</h1>
    <!-- 房间添加表单 -->
    <form @submit.prevent="addRoom">
      <input
          type="text"
          v-model="newRoomName"
          placeholder="输入房间名称"
          required
      />
      <button type="submit">添加房间</button>
    </form>
    <!-- 房间列表展示 -->
    <ul>
      <li v-for="(room, index) in rooms" :key="index">
        {{ room }}
        <button @click="deleteRoom(index)">删除</button>
      </li>
    </ul>
  </div>
</template>

<script setup>
import { ref } from 'vue';

// 定义房间列表的响应式数据
const rooms = ref([]);
// 定义新房间名称的响应式数据
const newRoomName = ref('');

// 添加房间的方法
const addRoom = () => {
  if (newRoomName.value.trim() !== '') {
    rooms.value.push(newRoomName.value);
    newRoomName.value = '';
  }
};

// 删除房间的方法
const deleteRoom = (index) => {
  rooms.value.splice(index, 1);
};
</script>

<style scoped>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}

input {
  padding: 8px;
  margin-right: 10px;
}

button {
  padding: 8px 16px;
  background-color: #42b983;
  color: white;
  border: none;
  cursor: pointer;
}

button:hover {
  background-color: #357a5e;
}

ul {
  list-style-type: none;
  padding: 0;
}

li {
  margin: 10px 0;
}
</style>